# -*- coding: utf-8 -*-            
# @Author : HJH
# @Time : 2024/7/14 14:46
# @Use :
import json

import requests

if __name__ == '__main__':
    dep = 'CGQ'
    arr = 'HGH'
    flight_no = 'GJ8994'
    dep_date = '2024-09-01'
    ac_code = flight_no[:2]

    avh_res = requests.get(url=f"http://localhost:6181/api/raw/avh/{dep}{arr}/{dep_date}/{ac_code}")

    print(avh_res.text)

    avh_json = json.loads(avh_res.text)

    flight_info = [aj for aj in avh_json['data'] if aj['flightNo'] == flight_no][0]

    res_datas = []
    for c in flight_info['cabin']:
        if c['cnum'] == 0:
            continue

        pat_res = requests.get(url=f"http://localhost:6181/api/raw/pat/{flight_no}/{dep}/{arr}/{c['cbn']}/{dep_date}")
        cabin_price = json.loads(pat_res.text)

        new_item = dict()
        new_item['dep'] = dep
        new_item['arr'] = arr
        new_item['flight_no'] = flight_no
        new_item['dep_date'] = dep_date
        new_item['cabin'] = c['cbn']

        if cabin_price['code'] != 0:
            new_item['msg'] = cabin_price['message']
            continue

        for cp in cabin_price['data']['data']:
            new_item[cp['priceCode']] = cp['cnyf']

        res_datas.append(new_item)

    print(json.dumps(res_datas))
